package best.driver.android.Utils;

import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import best.driver.android.Activity.Base.BaseActivity;
import best.driver.android.View.BestAlertDialog;
import best.driver.android.View.BestAlertDialogBase;
import best.driver.android.View.BestEditTextDialog;

public class DialogUtil {

    public static BestAlertDialog alert(Activity activity, String content) {
        return alert(activity, null, content, null, null, null);
    }

    public static BestAlertDialog alert(
            Activity activity,
            String content,
            BestAlertDialogBase.BestAlertDialogOnClickListener onClickListener) {
        return alert(activity, null, content, null, null, onClickListener);
    }

    public static BestAlertDialog alert(
            Activity activity,
            String title, String content) {
        return alert(activity, title, content, null, null, null);
    }

    public static BestAlertDialog alert(
            Activity activity,
            String title, String content,
            BestAlertDialogBase.BestAlertDialogOnClickListener onClickListener) {
        return alert(activity, title, content, null, null, onClickListener);
    }

    public static BestAlertDialog alert(
            Activity activity,
            String title,
            String content,
            String okButtonText,
            String cancelButtonText,
            BestAlertDialogBase.BestAlertDialogOnClickListener onClickListener) {

        try {
            if (activity != null &&
                    ((activity instanceof BaseActivity && ((BaseActivity) activity).destroyed()))) {
                return null;
            }
            BestAlertDialog alertDialog = new BestAlertDialog(activity, onClickListener);
            if (TextUtils.isEmpty(cancelButtonText)) {
                alertDialog.setCancelButtonVisible(View.GONE);
            }
            alertDialog.setButtonText(cancelButtonText, okButtonText);
            alertDialog.show(title, content);
            return alertDialog;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static BestEditTextDialog prompt(Activity activity,
                                           String title,
                                           String hint,
                                           String okButtonText,
                                           String cancelButtonText,
                                           BestAlertDialogBase.BestAlertDialogOnClickListener onClickListener) {
        try {
            if (activity != null &&
                    ((activity instanceof BaseActivity && ((BaseActivity) activity).destroyed()))) {
                return null;
            }

            BestEditTextDialog edjEditTextDialog = new BestEditTextDialog(activity, onClickListener);
            if (TextUtils.isEmpty(cancelButtonText)) {
                edjEditTextDialog.setCancelButtonVisible(View.GONE);
            }
            edjEditTextDialog.setButtonText(cancelButtonText, okButtonText);
            edjEditTextDialog.show(title, hint);
            return edjEditTextDialog;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
